package com.ruoyi.datainterface.controller;


import cn.hutool.core.collection.CollectionUtil;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.LabinfoItemData;
import com.ruoyi.system.domain.LabinfoSampleData;
import com.ruoyi.system.domain.Patient;
import com.ruoyi.system.service.ILabinfoItemDataService;
import com.ruoyi.system.service.ILabinfoSampleDataService;
import com.ruoyi.system.service.PatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/check")
public class DataInterfaceController extends BaseController {

    @Autowired
    private PatientService patientService;

    @Autowired
    private ILabinfoItemDataService itemDataService;

    @Autowired
    private ILabinfoSampleDataService sampleDataService;

    /**
     * 新增患者主数据
     */
    @PreAuthorize("@ss.hasPermi('check:patient:save')")
    @Log(title = "患者主数据", businessType = BusinessType.SAVE)
    @PostMapping("/patient/save")
    public AjaxResult patientSave(@RequestBody List<Patient> patientList)
    {
        if(CollectionUtil.isNotEmpty(patientList)){
            String message = patientService.savePatient(patientList);
            return success(message);
        }else {
            return error("数据不能为空");
        }
    }

    /**
     * 保存item数据
     */
    /**
     * 新增患者主数据
     */
    @PreAuthorize("@ss.hasPermi('check:item:save')")
    @Log(title = "患者item数据", businessType = BusinessType.SAVE)
    @PostMapping("/item/save")
    public AjaxResult itemSave(@RequestBody List<LabinfoItemData> itemList)
    {
        if(CollectionUtil.isNotEmpty(itemList)){
            return itemDataService.saveItem(itemList);
        }else {
            return AjaxResult.error("数据不能为空");
        }
    }

    /**
     * 保存item数据
     */
    /**
     * 新增患者主数据
     */
    @PreAuthorize("@ss.hasPermi('check:sample:save')")
    @Log(title = "患者样本数据", businessType = BusinessType.SAVE)
    @PostMapping("/sample/save")
    public AjaxResult sampleSave(@RequestBody List<LabinfoSampleData> sampleDataList)
    {
        if(CollectionUtil.isNotEmpty(sampleDataList)){
            return sampleDataService.saveSample(sampleDataList);
        }else {
            return AjaxResult.error("数据不能为空");
        }
    }

}
